package br.com.fabrica.aid.aid_fabrica.view;

import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;

import br.com.fabrica.aid.aid_fabrica.business.MontagemBC;
import br.com.fabrica.aid.aid_fabrica.domain.Montagem;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;

@ViewController
@NextView("./montagem_edit.xhtml")
@PreviousView("./montagem_list.xhtml")
public class MontagemListMB extends AbstractListPageBean<Montagem, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private MontagemBC mo;

	@Override
	protected List<Montagem> handleResultList() {
		return this.mo.findAll();
	}

	@Transactional
	public String deleteSelection() {
		boolean delete;
		for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
			Long idmontagem = iter.next();
			delete = getSelection().get(idmontagem);

			if (delete) {
				mo.delete(idmontagem);
				iter.remove();
			}
		}
		return getPreviousView();
	}

}